package com.example.webpractice.service;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.webpractice.dao.UserDao;
import com.example.webpractice.po.UserPO;
import com.example.webpractice.vo.UserVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 系统用户
 */
@Service("userService")
public class UserService {

    @Autowired
    private UserDao dao;

    public UserPO selectByUsername(String username) {
        return dao.selectOne(new QueryWrapper<UserPO>().eq("username", username));
    }

    public void create(UserPO user) {
        dao.insert(user);
    }

    public int updateUser(UserPO userPO) {
        return dao.updateById(userPO);
    }

    public UserVO selectById(Long id) {
        UserPO po = dao.selectOne(new QueryWrapper<UserPO>().eq("id", id));
        UserVO vo = new UserVO();
        BeanUtils.copyProperties(po, vo);
        return vo;
    }
}


